package plugin.live.redis.queue;

import java.io.Serializable;
import java.util.List;

import com.jfinal.plugin.redis.Cache;
import com.jfinal.plugin.redis.Redis;

import lombok.extern.slf4j.Slf4j;
/**
 * 队列.默认去食堂排队打饭
 * @author Administrator
 *
 * @param <T>
 */
@Slf4j
public class RedisQueue<T> implements Serializable {
	private static final long serialVersionUID = 1796841138519234801L;
	
	private String key;
	public RedisQueue(String cacheNmae) {
		this.key = cacheNmae;
	}
	
	/**
	 * 去排队,增加到最后面
	 * @param t
	 */
	public void pushLast(T t) {
		Cache cache = Redis.use();
		cache.rpush(key, t);// 新增到最后
		log.debug("新增队列:"+t);
	}
	
	/**
	 * 取出并队伍删除第一个
	 * @return
	 */
	public T pullFristOne() {
		Cache cache = Redis.use();
		T lpop = cache.lpop(key);
//		log.debug("取出队列:"+lpop);
		return lpop;
	}
	
	public List<T> getList(){
		Cache cache = Redis.use();
		List<T> lrange = cache.lrange(key, 0, -1);
		return lrange;
	}
}
